﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Runtime.Serialization;

namespace PedesTrainProject.Grid
{
    [Serializable()]
    public class Grid : ISerializable
    {
        private int height = 4;

        public int Height
        {
          get { return height; }
          set { height = value; }
        }
        
        private List<Tile> tiles = new List<Tile>();

        public List<Tile> Tiles
        {
            get { return tiles; }
            set { tiles = value; }
        }
        private int width = 4;

        public int Width
        {
            get { return width; }
            set { width = value; }
        }

        

        public Grid()
        {
            tiles.Capacity = 16;
            for (int i = 0; i < 16; i++)
            {
                tiles.Add(new Tile(new Road("empty", "empty", Directions.None)));
            }
        }

        public Grid(int height = 4, int width = 4)
        {
            tiles.Capacity = 16;
            for (int i = 0; i < 16; i++)
            {
                tiles.Add(new Tile(new Road("empty","empty",Directions.None)));
            }
        }

        public Grid(List<Tile> _tiles, int height=4,int width=4)
        {
            tiles = _tiles;
            tiles.Capacity = 16;
            for (int i = 0; i < 16; i++)
            {
                tiles.Add(new Tile(new Road("empty", "empty", Directions.None)));
            }
        }
        public void addTile(Tile tile, Vector position) //++position
        {
            tiles[Core.Calculations.tileListPosition(Core.Calculations.calculateTileCoordinates(position))]=tile;
          //  System.Console.WriteLine(Core.Calculations.tileListPosition(Core.Calculations.calculateTileCoordinates(position)));
        }
      
        public void editTile(Tile tile, Vector positon)
        {

        }
        public void removeTile(Tile tile)
        {
        }

        public void removeTile(Vector position)
        {

        }

        #region Serialize
        public Grid(SerializationInfo info, StreamingContext ctxt)
        {
            this.height = (int)info.GetValue("Height", typeof(int));
            this.tiles = (List<Tile>)info.GetValue("Tiles", typeof(List<Tile>));
            this.width = (int)info.GetValue("Width", typeof(int));
        }

        public void GetObjectData(SerializationInfo info, StreamingContext ctxt)
        {
            info.AddValue("Height", this.height);
            info.AddValue("Tiles", this.tiles);
            info.AddValue("Width", this.width);
        }
        #endregion

    }
}
